package com.eilieili.lyq.supervideo;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Handler;
import android.os.Message;
import android.os.Bundle;
import android.util.Log;

public class SplashActivity extends Activity {

    private SharedPreferences mSharedPreferences;
    private static final int GO_HOME = 1;
    private static final int GO_GUIDE = 2;
    private static final int ENTREE_DURATION = 2000;
    private Handler mhandler = new Handler(){
        @Override
        public void handleMessage(Message msg) {
            switch (msg.what){
                case GO_GUIDE:
                    startGuideActivity();
                    break;
                case GO_HOME:
                    startHomeActivity();
                    break;
                default:
                    break;
            }
        }
    };

    private void startHomeActivity() {
        Intent intent = new Intent(SplashActivity.this,HomeActivity.class);
        startActivity(intent);
        finish();
    }

    private void startGuideActivity() {
        Intent intent = new Intent(SplashActivity.this,GuideActivity.class);
        startActivity(intent);
        finish();
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);
        mSharedPreferences = getSharedPreferences("config",MODE_PRIVATE);
        init();
    }

    private void init() {
        boolean isFirstIn = mSharedPreferences.getBoolean("mIsFirst",true);
        Log.e("SharedPreferences", "init: "+isFirstIn);
        if(isFirstIn){
            mhandler.sendEmptyMessageDelayed(GO_GUIDE,ENTREE_DURATION);
        }else{
            mhandler.sendEmptyMessageDelayed(GO_HOME,ENTREE_DURATION);
        }

    }
}
